package cn.common.config;

/**
 * Copyright
 *
 * @Author WuHuang
 * @Date 2022/12/22
 */


import cn.common.enums.EBusinessTypeEnum;

/**
 * @Classname Idc
 * @Description id生成工具类
 * @Date 2020-01-17 17:39
 * @Created by jacksondeng
 */
public class Idc {
    private static IdCreater idc = new IdCreater(EBusinessTypeEnum.DEFAULT.getBusinessId());


    public static Idc getInstance() {
        return Idc.IdcHolder.idc;
    }

    private static class IdcHolder {
        public static Idc idc = new Idc();
        private IdcHolder() {
        }
    }

    /**
     * 默认使用这个方法
     * @return
     */
    public long genenrator() {
        return idc.nextId();
    }

    /**
     *
     * @param businessId (业务标识4位)
     * @see com.tencent.sr.rmall.springbootstarter.enums.EBusinessTypeEnum
     * @param datacenterId (分库分表字段值的后8位,初期如果没有,可以传(0-255)的随机数)
     * @return
     */
    public long genenrator(long businessId, long datacenterId) {
        return idc.nextId(businessId, datacenterId);
    }

    /**
     *
     * @param businessId (业务标识4位)
     * @see com.tencent.sr.rmall.springbootstarter.enums.EBusinessTypeEnum
     * @param datacenterId (分库分表字段值的后8位，或者0-255的随机数)
     * @param reserved （预留位4位）
     * @return
     */
    public long genenrator(long businessId, long datacenterId, long reserved) {
        return idc.nextId(businessId, datacenterId, reserved);
    }

    /**
     * 只传入分库分表标识,用ip尾号隔离
     * @param datacenterId(分库分表字段值的后8位或者0-255的随机数)
     * @return
     */
    public long genenrator(long datacenterId) {
        return idc.nextId(datacenterId);
    }


}

